﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CMN.BLL;
using CMN.Common;
using CMN.Entity;
using CMN.Models.Interfaces;
namespace CMN.Models
{
    /// <summary>
    /// 模板皮肤Service
    /// </summary>
    public class Normal_SkinService: ISearchDataService<Normal_SkinEntity>
    {
        /// <summary>
        /// 新增模板皮肤
        /// </summary>
        /// <param name="Normal_SkinEntity"></param>
        /// <returns>bool</returns>
        public string Insert(Normal_SkinEntity normal_skinEntity)
        {
            Normal_Skin bll = new Normal_Skin();
            normal_skinEntity.DataTable_Action = DataTableAction.Insert;
            if (bll.DirIsExist(normal_skinEntity.Dir) <= 0)
            {
                if (bll.InsertUpdateDelete(normal_skinEntity) > 0)
                {
                    return "";
                }
                else
                {
                    return "失败";
                }
            }
            else
            {
            
                return "失败";
            
            }
        }

        /// <summary>
        /// 是否存在该模板皮肤
        /// </summary>
        /// <param name="dir"></param>
        /// <returns></returns>
        public int IsHas(string dir)
        {
            Normal_Skin bll = new Normal_Skin();
            return bll.DirIsExist(dir);
        }

        /// <summary>
        /// 返回模板皮肤查询列表
        /// </summary>
        /// <param name="qp"></param>
        /// <param name="count">查询总个数</param>
        /// <returns>List</returns>
        public List<Normal_SkinEntity> List(QueryParam qp,out int count)
        {
            Normal_Skin bll = new Normal_Skin();
            return bll.List(qp, out count);
        }

        /// <summary>
        /// 更新模板皮肤
        /// </summary>
        /// <param name="Normal_Skin"></param>
        /// <returns>bool</returns>
        public string Update(Normal_SkinEntity normal_skinEntity)
        {
            Normal_Skin bll = new Normal_Skin();
            normal_skinEntity.DataTable_Action = DataTableAction.Update;
            if (bll.InsertUpdateDelete(normal_skinEntity) > 0)
            {
                return "";
            }
            else
            {
                return "失败";
            }
        }

        /// <summary>
        /// 删除模板皮肤
        /// </summary>
        /// <param name="Normal_Skin"></param>
        /// <returns>bool</returns>
        public string Delete(Normal_SkinEntity normal_skinEntity)
        {
            Normal_Skin bll = new Normal_Skin();
            normal_skinEntity.DataTable_Action = DataTableAction.Delete;
            if (bll.InsertUpdateDelete(normal_skinEntity) > 0)
            {
                return "";
            }
            else
            {
                return "失败";
            }
        }

        /// <summary>
        /// 批量删模板皮肤
        /// </summary>
        /// <param name="idList">删除id列表  2_8_9_45</param>
        /// <returns>bool</returns>
        public string DeleteList(string idList)
        {
            Normal_Skin bll = new Normal_Skin();
            string[] list =Utils.SplitString(idList,"_");
            string strDel=Utils.ArrayToString(list,",",false);
            if (bll.DelList(strDel) > 0)
            {
                return "";
            }
            else
            {
                return "失败";
            }

        }

        /// <summary>
        /// 返回单个模板皮肤
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Normal_SkinEntity</returns>
        public Normal_SkinEntity Look(int id)
        {
            Normal_Skin bll = new Normal_Skin();
            return bll.Disp(id);
        }
    }
}
